<template>
  <div class="app-container order-detail-page">
    <!-- 信息 -->
    <el-descriptions
      class="margin-top"
      title="会员用户详情"
      :column="3"
      :size="size"
      border
    >
      <!-- <template slot="extra">
        <el-button type="primary" size="small">操作</el-button>
      </template> -->
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-user"></i>
          头像
        </template>
        <img width="40px" height="40px" :src="detailInfo.avatar" />
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-user"></i>
          用户昵称
        </template>
        {{ detailInfo.nickname }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-user"></i>
          用户姓名
        </template>
        {{ detailInfo.name }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-mobile-phone"></i>
          手机号
        </template>
        {{ detailInfo.mobile }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          算力
        </template>
        {{ detailInfo.point }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          总算力
        </template>
        {{ detailInfo.totalPoint }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          id码
        </template>
        {{ detailInfo.idCode }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          性别
        </template>
        {{ detailInfo.sex }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          所在地
        </template>
        {{ detailInfo.areaName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          出生日期
        </template>
        {{ detailInfo.birthday }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          备注
        </template>
        {{ detailInfo.mark }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          会员标签
        </template>
        {{ detailInfo.tagNames }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          会员等级
        </template>
        {{ detailInfo.levelName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          会员分组
        </template>
        {{ detailInfo.groupName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          用户经验值
        </template>
        {{ detailInfo.experience }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          最后登录时间
        </template>
        {{ detailInfo.loginDate }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          创建时间
        </template>
        {{ detailInfo.createTime }}
      </el-descriptions-item>

      <el-descriptions-item   >
        <template slot="label">
          <i class="el-icon-tickets"></i>
          推荐我注册的用户名(点击查看)
        </template>
        <span  @click="goreferencedetail()" style="color: cornflowerblue;"  > {{ detailInfo.reference ? detailInfo.reference.name : "-" }}</span>
      
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          推荐我注册的用户手机号
        </template>
        {{ detailInfo.reference ? detailInfo.reference.mobile : "-" }}
      </el-descriptions-item>
    </el-descriptions>
    <div v-if="referrerData.length > 0">
      <div>
        <h1 class="title-re">我推荐注册的用户</h1>
        <el-divider></el-divider>
      </div>

      <el-table :data="referrerData" stripe style="width: 100%">
        <el-table-column label="用户ID" width="180" prop="id">
        </el-table-column>
        <el-table-column prop="nickname" label="用户昵称" width="180">
        </el-table-column>
        <el-table-column prop="mobile" label="手机号"> </el-table-column>
        <el-table-column prop="idCode" label="idCode"> </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template v-slot="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="godetail(scope.row.id)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getRefereeUserPage"
      />
    </div>
  </div>
</template>

<script>
import * as memberApi from "@/api/member";
export default {
  name: "MemberDetail",
  data() {
    return {
      detailInfo: {},
      referrerData: [],
      total: 0,
      queryParams: {
        userId: "",
        pageNo: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    console.log("created");
    memberApi.getMemberDetail(this.$route.query.id).then((res) => {
      this.detailInfo = res.data;
    });
    this.queryParams.userId = this.$route.query.id;
    this.getRefereeUserPage();
  },

  watch: {
    "$route.query.id": "fetchMemberDetail",
  },

  methods: {
    clipboardSuccess() {
      this.$modal.msgSuccess("复制成功");
    },
    /** 会员用户详情 */
    godetail(row) {
      this.$router.push({ name: "MemberDetail", query: { id: row } });
    },
    goreferencedetail(){
      console.log("goreferencedetailxxxx");
      
        if(this.detailInfo.reference){
           this.godetail(this.detailInfo.reference.id)
        }
    },
    getRefereeUserPage() {
      memberApi.getRefereeUserPage(this.queryParams).then((res) => {
        console.log("res", res);
        this.referrerData = res.data.list;
        this.total = res.data.total;
      });
    },
    fetchMemberDetail() {
      console.log("Fetching member detail");
      if (this.$route.query.id) {
        memberApi.getMemberDetail(this.$route.query.id).then((res) => {
          this.detailInfo = res.data;
        });
        this.queryParams.userId = this.$route.query.id;
        this.getRefereeUserPage();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.title-re {
  text-align: center;
  font-weight: 700;
}
:deep(.el-descriptions) {
  &:not(:nth-child(1)) {
    margin-top: 20px;
  }
  .el-descriptions__title {
    display: flex;
    align-items: center;
    &::before {
      content: "";
      display: inline-block;
      margin-right: 10px;
      width: 3px;
      height: 20px;
      background-color: #409eff;
    }
  }
  .el-descriptions-item__container {
    margin: 0 10px;
    .no-colon {
      margin: 0;
      &::after {
        content: "";
      }
    }
  }
}
</style>
